package com.monster.service;

import com.monster.dao.SongDao;
import com.monster.dao.SongDaoImpl;
import com.monster.pojo.Singer;
import com.monster.pojo.Song;

import java.util.ArrayList;

/**
 * 歌曲详情页面的业务逻辑层实现类
 * @author cyb
 */
public class SongServiceImpl implements SongService {
    private SongDao sdi = new SongDaoImpl();

    @Override
    public Song getSongById(Long id) {
        Song song = sdi.getSongById(id);
        song.setAlbum(sdi.getAlbumBySongId(id));
        song.setSingers(sdi.listSingersBySongId(id));
        song.setPlaylist(sdi.listPlaylistsBySongId(id));
        return song;
    }

    @Override
    public ArrayList<Song> listSongs(ArrayList<Long> songsId) {
        ArrayList<Song> songs = null;
        if (songsId.size() > 0) {
            songs = new ArrayList<>(songsId.size());
        }
        for (Long songId : songsId) {
            Song song = sdi.getSimpleSongById(songId);      // 获得song的id、name、time
            song.setSingers(sdi.listSingersBySongId(songId));       // 获得song的singer
            song.setAlbum(sdi.getAlbumBySongId(songId));        // 获得song的album
            songs.add(song);
        }
        return songs;
    }

    @Override
    public ArrayList<Song> listSongsByFuzzy(String key) {
        return sdi.listSongsByFuzzy(key);
    }

}
